﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _7.SelectionSort
{
    class SelectionSort
    {
        static void Main(string[] args)
        {
            Console.WriteLine("n=");
            int n = int.Parse(Console.ReadLine());
            int[] arrayN;
            arrayN = new int[n];
            if (n > 1)
            {
                for (int i = 0; i < arrayN.Length; i++)
                {
                    Console.Write("[{0}]=",i);
                    arrayN[i] = int.Parse(Console.ReadLine());
                    Console.WriteLine();
                }
                int tmp, prevEl;
                for (int i = 0; i < arrayN.Length - 1; i++)
                {

                    prevEl = i;
                    for (int j = i+1; j < arrayN.Length; j++)
                    {

                        if (arrayN[j]<arrayN[prevEl])
                        {
                            prevEl = j;   
                        }
                    }
                    tmp = arrayN[prevEl];
                    arrayN[prevEl] = arrayN[i];
                    arrayN[i] = tmp;

                }
                Console.WriteLine("Selection sort:");
                for (int i = 0; i < arrayN.Length; i++)
                {
                    Console.WriteLine("[{0}]={1}",i,arrayN[i] );
                }
            }
        }
    }
}
